#ifndef APPMENU_UPDATER_H
#define APPMENU_UPDATER_H

#include <unordered_map>
#include <memory>
#include <utility>
using std::auto_ptr;
using std::pair;

#include <sys/types.h>
#include <glibmm/ustring.h>
#include <sigc++/signal.h>

namespace Gtk {
    class Menu;
    class MenuItem;
} /* Gtk forward declaration */

class process_t;
class configuration;
class preferences_dialog;
class _AppIndicator; 
/* I use _AppIndicator here to resolve the conflicts between
 * typedef and forward declaration. (remove the '_' and see what happens)
 * This may broke in future */

class appmenu_updater {
public:
    appmenu_updater (configuration&);

	/* called when a new process is added */
	void process_added (const process_t&);

	/* called when a new process is removed */
    void process_removed (pid_t);	

	/* called when a new process is updated */
    void process_updated (const process_t&);	

    /* refresh system information */
    void sys_update (const process_t&);

    /* GUI related slots */
    void activate_quit ();
    void activate_pref ();

private:
    /* store current state */
    int state_;

	/* appindicator handle */
    _AppIndicator *indicator_;

    /* appindicator menu */
    auto_ptr<Gtk::Menu> menu_;

    /* preferences dialog */
    auto_ptr<preferences_dialog> dialog_;

    /* the process list */
    typedef std::unordered_map<pid_t, Gtk::MenuItem*> process_menu_lists_t;
    process_menu_lists_t process_menu_lists_;

    /* configuration file */
    configuration &config_;

    /* indicates whether list is empty */
    bool empty_;

    /* utils */
    Glib::ustring get_process_markup (const process_t &);
    Gtk::MenuItem* add_menu_item (pid_t, const Glib::ustring&);
    void add_no_process ();
};

#endif /* end of APPMENU_UPDATER_H */
